package com.mew.chess.core.game.dyj.game.message;

import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@Data
@ToString
@NoArgsConstructor
public class EnterResponseMessage extends ZebraBaseMessage<EnterResponseMessage> {

    private UserMessage userMessage;
    private int[] roomBetArray;
    private long lastBetNumber; // 上把 押注

    private int linkType;
    private int remainTime;

    private long ino;//局号

    private long roomCost;//房费

    private Map<Integer,Long> typebetNumber;//各个区域压注
    private long[][] playerTypeBetNumber;//各个区域玩家压注
    private List<Integer> dices;//骰子
    private HistoryMessage history;    //历史记录
    private Collection<UserMessage> bigRList;    //大玩家

    @Override
    public void write(ByteBuf b) {

        userMessage.write(b);
        writeIntArray(b, this.roomBetArray);
        writeLong(b, this.lastBetNumber);
        writeInt(b, this.linkType);
        writeInt(b, this.remainTime);

        writeLong(b, ino);
        writeLong(b, this.roomCost);

        writeInt(b,typebetNumber.size());
        typebetNumber.entrySet().stream().forEach(entry->{
            writeInt(b,2);
            writeLong(b,entry.getKey());
            writeLong(b,entry.getValue());
        });

        writeInt(b,playerTypeBetNumber.length);
        for (long[] aLong : playerTypeBetNumber) {
            writeInt(b,aLong.length);
            for (long l : aLong) {
                writeLong(b,l);
            }
        }

        writeInt(b,dices.size());
        for (Integer dice : dices) {
            writeInt(b,dice);
        }
        history.write(b);
        writeInt(b,bigRList.size());
        for (UserMessage userMessage : bigRList) {
            userMessage.write(b);
        }
    }

    @Override
    public EnterResponseMessage read(ByteBuf b) {
        EnterResponseMessage message = new EnterResponseMessage();
        UserMessage userMessage = new UserMessage();
        userMessage.read(b);
        message.setUserMessage(userMessage);
        message.roomBetArray = readIntArray(b);
        message.lastBetNumber = readLong(b);
        message.linkType = readInt(b);
        message.remainTime = readInt(b);

        return message;
    }
}
